package com.rd.teacher.jichao.day12;

public class TestOrderPrint {

    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println("1");

            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                    t1.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    throw new RuntimeException();
                }
                System.out.println("2");

            }
        });
        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                    t2.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    throw new RuntimeException();
                }
                System.out.println("3");

            }
        });

        //t1 t2 t3 的顺序执行也可以 但是有隐患
        t1.start();
        t2.start();
        t3.start();

        // 像栈的结构一样
        // 更建议的写法
//        t3.start();
//        t2.start();
//        t1.start();
    }
}
